package com.kyc.kycxkplaygame.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.kyc.kycxkplaygame.R;
import com.kyc.kycxkplaygame.util.MyScrollView;
import com.kyc.kycxkplaygame.util.ScrollViewListener;
import com.kyc.kycxkplaygame.util.SharedPreferencesUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private MyScrollView scrollview;
    private int level;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        scrollview = (MyScrollView) findViewById(R.id.scrollview);


        //SharedPreferencesUtils.putHashMapData(MainActivity.this,"level_pass",map);
       // HashMap<String, String> levelPass = SharedPreferencesUtils.getHashMapData(MainActivity.this, "level_pass", String.class);
        //list.add(levelPass);

        scrollview.setOnclick(new ScrollViewListener() {
            @Override
            public void myOnclick(int current) {
                //Toast.makeText(MainActivity.this,"当前点击了=" + current,Toast.LENGTH_SHORT).show();
                if(current > level) {
                    return;
                }
                Intent intent = new Intent(MainActivity.this, StartPlayActivity.class);
                if ( String.valueOf(current).length() == 1) {
                    intent.putExtra("level_num", "0"+String.valueOf(current));
                } else {
                    intent.putExtra("level_num", String.valueOf(current));
                }
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        level = (int) SharedPreferencesUtils.getParam(MainActivity.this, "level", 1);

        List<Map<String,String>> list = new ArrayList<>();
        Map<String,String> map = new HashMap<>();
        map.put("type", String.valueOf((level)));
        list.add(map);
        scrollview.setMapList(list);
    }

    @Override
    protected void onStop() {
        super.onStop();
        scrollview.recyleBitmap();
    }
}
